<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    
    //登录页面
    public function login($host='',$port='',$dbname='',$username='',$userpassword=''){
        if(IS_POST){
            //配置动态设置
            $MySQLConfig= array(
                'db_type'  => 'mysql',
                'db_user'  => $username,
                'db_pwd'   => $userpassword,
                'db_host'  => $host,
                'db_port'  => $port,
                'db_name'  => $dbname
            );
            S('MySQLConfig',$MySQLConfig); 
            $this->success('连接成功', U('index/index'));
             
        }else{
            $this->display();
        }
    }


    public function index(){
        $MySQLConfig=S('MySQLConfig');  
        $db = M("","",$MySQLConfig);  
        $tables= $db->query($sql = 'show tables');
        $fixstr="tables_in_".$MySQLConfig['db_name']; 
        for($i=0;$i<count($tables);$i++){            
          $tableslist[$i]= $tables[$i][$fixstr];
        }
        
        $this->assign('MySQLConfig',$MySQLConfig);
       
        $this->assign('tables',$tableslist);
        $this->display();
    }
    
    
}